package cn.zyq.demo.controller.mgt.system;


import cn.zyq.demo.service.sys.SysConfigService;
import cn.zyq.demo.service.sys.SysRegisterService;
import cn.zyq.demo.system.common.BaseController;
import cn.zyq.demo.system.exception.BusinessException;
import cn.zyq.demo.system.ry.model.RegisterBody;
import cn.zyq.demo.system.ry.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 注册验证
 *
 * @author ruoyi
 */
@RestController
public class SysRegisterController extends BaseController {
    @Autowired
    private SysRegisterService registerService;

    @Autowired
    private SysConfigService configService;

    @PostMapping("/mgt/register")
    public Object register(@RequestBody RegisterBody user) {
        if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
            throw new BusinessException("当前系统没有开启注册功能！");
        }
        String msg = registerService.register(user);
        if (StringUtils.isEmpty(msg)) {
            return "注册成功";
        }
        throw new BusinessException(msg);
    }
}
